package initiallize

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"os"
	"path/filepath"
	"shop_webs/oss_web/middlewares"
	"shop_webs/oss_web/router"
)

var (
	dir, _ = os.Getwd()
)

func Routers() *gin.Engine {
	Router := gin.Default()

	Router.LoadHTMLFiles(filepath.Join(dir, "oss_web", "templates", "index.html"))
	Router.StaticFS("/static", http.Dir(filepath.Join(dir, "oss_web", "static")))
	Router.GET("", func(context *gin.Context) {
		context.HTML(http.StatusOK, "index.html", gin.H{
			"title": "posts/index",
		})
	})

	Router.Use(middlewares.Cors())
	ApiGroup := Router.Group("/oss/v1")
	router.InitOssRouter(ApiGroup)

	return Router
}
